﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for AutoSentEmailSettingDAO
/// </summary>
public class AutoSentEmailSettingDAO
{
    SqlHelp help = new SqlHelp();
	public AutoSentEmailSettingDAO()
	{	}

    public int AddUpdateAutoSentEmail(AutoSentEmailSettingModel model)
    {
        SqlParameter[] paras = new SqlParameter[] 
            { new SqlParameter("@DateColumnType1",model.DateColumnType1),
              new SqlParameter("@DateDay1",model.DateDay1),
              new SqlParameter("@DateColumnType2",model.DateColumnType2),
              new SqlParameter("@DateDay2",model.DateDay2),
              new SqlParameter("@DateColumnType3",model.DateColumnType3),
              new SqlParameter("@DateDay3",model.DateDay3),
              new SqlParameter("@DateTypeValue",model.DateTypeValue),
              new SqlParameter("@UserCode",model.UserCode),
              new SqlParameter("@CoCode",model.UserCode)
            };
        return help.RunProcInt("AddUpdateAutoSentEmail", paras);
    }

    public ExportExcelModel GetShowColumnsAutoSentEmail()
    {
        ExportExcelModel model = new ExportExcelModel();

        string[] strColumns = new string[] { "", "" };
        List<List<string>> columnsList = new List<List<string>>();
        List<string> columnName = new List<string>();
        List<string> columnShowName = new List<string>();

        DataTable dt = help.RunDataTableProc("GetShowColumnsAutoSentEmail", null);
        if (dt != null && dt.Rows.Count > 0)
        {
            foreach (DataRow row in dt.Rows)
            {
                columnName.Add(row["ColumnType"].ToString());
                columnShowName.Add(row["ColumnName"].ToString());
                strColumns[0] += row["ColumnType"] + ",";
                strColumns[1] += row["ColumnName"] + ",";
            }
            strColumns[0] = strColumns[0].Substring(0, strColumns[0].Length - 1);
            strColumns[1] = strColumns[1].Substring(0, strColumns[1].Length - 1);
        }
        columnsList.Add(columnName);
        columnsList.Add(columnShowName);

        model.columns = strColumns;
        model.columnsList = columnsList;
        return model;
    }

    public DataTable GetDataAutoSentEmail(ExportExcelModel model)
    {
        return help.RunDataTableProc("GetDataAutoSentEmail", new SqlParameter[] { new SqlParameter("@Columns", model.columns[0]) });
    }

}